Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/codegen): Fix codegen of large numeric literals #9226

Merged
merged 13 commits into from
Jul 15, 2024

Conversation

imranbarbhuiya
Copy link
Contributor

@imranbarbhuiya imranbarbhuiya commented Jul 12, 2024

Description:

This PR moves the infinite check below the raw number check

Related issue:

@imranbarbhuiya imranbarbhuiya requested a review from a team as a code owner July 12, 2024 17:52
@CLAassistant
Copy link

CLAassistant commented Jul 12, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@imranbarbhuiya imranbarbhuiya marked this pull request as draft July 12, 2024 18:11
Copy link

codspeed-hq bot commented Jul 12, 2024

CodSpeed Performance Report

Merging #9226 will not alter performance

Comparing imranbarbhuiya:fix/infinite (c82f0cf) with imranbarbhuiya:fix/infinite (7f5139b)

Summary

✅ 178 untouched benchmarks

@imranbarbhuiya imranbarbhuiya marked this pull request as ready for review July 13, 2024 21:46
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc-bump:

  • swc_core
  • swc_ecma_codegen

crates/swc_ecma_codegen/src/lib.rs Outdated Show resolved Hide resolved
} else {
match &num.raw {
Some(raw) => {
if raw.len() > 2 && self.cfg.target < EsVersion::Es2015 && {
let slice = &raw.as_bytes()[..2];
slice == b"0b" || slice == b"0o" || slice == b"0B" || slice == b"0O"
} {
value = num.value.to_string();
self.wr.write_str_lit(DUMMY_SP, &value)?;
if num.value.is_infinite() && num.raw.is_some() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this logic duplicate of the logic above?

Copy link
Contributor Author

@imranbarbhuiya imranbarbhuiya Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if part is same but else part isn't. And I can't move the if part above this match as this part is only needed for first branch of the match and not for others and they don't use .value directly instead performs operations to raw

@kdy1 kdy1 added this to the Planned milestone Jul 14, 2024
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


swc-bump:

  • swc_core
  • swc_ecma_codegen

@kdy1 kdy1 enabled auto-merge (squash) July 15, 2024 03:54
@kdy1 kdy1 changed the title fix: large numeric literals fix(es/codegen): Fix codegen of large numeric literals Jul 15, 2024
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review comment generated by auto-rebase script

Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review comment generated by auto-rebase script

@kdy1 kdy1 disabled auto-merge July 15, 2024 06:22
@kdy1 kdy1 merged commit fba79e6 into swc-project:main Jul 15, 2024
154 checks passed
@imranbarbhuiya imranbarbhuiya deleted the fix/infinite branch July 15, 2024 07:35
@kdy1 kdy1 modified the milestones: Planned, v1.7.0 Jul 17, 2024
@swc-project swc-project locked as resolved and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Large numeric literals are emitted as Infinity / -Infinity instead of remaining as they are.
4 participants